/**
 * Created by YangYan on 2016/5/22.
 */
(function () {
    //console.log(3);
    function Range(from,to){
        this.from=from;
        this.to=to;
    };
    Range.prototype={
        includes:function (x) {
            return this.from <=x && this.to >=x;
        },
        foreach:function (f) {
            for(var x=Math.ceil(this.from);x<this.to;x++) f;
        },
        toString:function () {
            return "("+this.from+"..."+this.to+")";
        }
    };
    var r=new Range(1,3);//如果var r=Range(1,3),则会报错。
    //console.log(r);
    //console.log(r.includes(2));
   // console.log(r.foreach(console.log(333)));
    //--------------------------------------------------------
    var F=function(){};
    var p=F.prototype;//这是F相关联的原型对象
    var c=p.constructor;//这是与原型相关联的函数
    console.log(c===F);//对于任意函数：F.prototype.constructor=F

    var o=new F();
    c.constructor===F;
    //--------------------------------------------------------

    Range.prototype={
        construtor:Range,
        includes:function (x) {
            return this.from <=x && this.to >=x;
        },
        foreach:function (f) {
            for(var x=Math.ceil(this.from);x<this.to;x++) f;
        },
        toString:function () {
            return "("+this.from+"..."+this.to+")";
        }
    };
    //---------------------------------------------------------
    Range.prototype.includes=function (x) {
        return this.from <=x && this.to >=x;
    };
    Range.prototype.foreach=function (f) {
        for(var x=Math.ceil(this.from);x<this.to;x++) f;
    };
    Range.prototype.toString=function () {
        return "("+this.from+"..."+this.to+")";
    };

    //----------------------------------------------------------
    function extend(o,p){
        for(prop in p){
            o[prop]=p[prop];
        }
        return o;
    };
    function defineClass(construtor,methods,statics){
        if(methods) extend(construtor.prototype,methods);
        if(statics) extend(construtor,statics);
        return construtor;
    };
    var SimpleRange=defineClass(
        function(f,t){this.f=f;this.t=t;},
        {includes:function (x) {return this.f<=x && x<=this.t;},
         toString:function(){return this.f+"..."+this.t;}
        },
        {upto:function(t){return new SimpleRange(o,t);}});
    //----------------------------------------------------------
})()